package cn.bornsoft.mobileServer.db;

import java.sql.Timestamp;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * JkIndexFlash entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see cn.bornsoft.mobileServer.db.JkIndexFlash
 * @author MyEclipse Persistence Tools
 */

public class JkIndexFlashDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory.getLog(JkIndexFlashDAO.class);
	// property constants
	public static final String TITLE = "title";
	public static final String CLASSNAME = "classname";
	public static final String PICPATH = "picpath";
	public static final String ORDERNUM = "ordernum";
	public static final String CLASSID = "classid";

	public void save(JkIndexFlash transientInstance) {
		log.debug("saving JkIndexFlash instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(JkIndexFlash persistentInstance) {
		log.debug("deleting JkIndexFlash instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public JkIndexFlash findById(java.lang.String id) {
		log.debug("getting JkIndexFlash instance with id: " + id);
		try {
			JkIndexFlash instance = (JkIndexFlash) getSession().get(
					"cn.bornsoft.mobileServer.db.JkIndexFlash", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(JkIndexFlash instance) {
		log.debug("finding JkIndexFlash instance by example");
		try {
			List results = getSession().createCriteria(
					"cn.bornsoft.mobileServer.db.JkIndexFlash").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding JkIndexFlash instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from JkIndexFlash as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	public List findByTitle(Object title) {
		return findByProperty(TITLE, title);
	}

	public List findByClassname(Object classname) {
		return findByProperty(CLASSNAME, classname);
	}

	public List findByPicpath(Object picpath) {
		return findByProperty(PICPATH, picpath);
	}

	public List findByOrdernum(Object ordernum) {
		return findByProperty(ORDERNUM, ordernum);
	}

	public List findByClassid(Object classid) {
		return findByProperty(CLASSID, classid);
	}

	public List findAll() {
		log.debug("finding all JkIndexFlash instances");
		try {
			String queryString = "from JkIndexFlash";
			getSession().clear();// 清除查询缓存
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public JkIndexFlash merge(JkIndexFlash detachedInstance) {
		log.debug("merging JkIndexFlash instance");
		try {
			JkIndexFlash result = (JkIndexFlash) getSession().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(JkIndexFlash instance) {
		log.debug("attaching dirty JkIndexFlash instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(JkIndexFlash instance) {
		log.debug("attaching clean JkIndexFlash instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}